package com.laiyima.zhongjiang.linghuilv.demo.home;

import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.laiyima.zhongjiang.linghuilv.demo.R;
import com.laiyima.zhongjiang.linghuilv.demo.util.FixedEditText;

import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import me.imid.swipebacklayout.lib.app.SwipeBackActivity;

public class ShowAddtaxActivity extends SwipeBackActivity implements View.OnClickListener {
    private FixedEditText show_addType,show_addEm,show_addBname,show_addpID,show_addTaxNo,show_addBank,show_addTMoblie,show_addAmount,show_addPName,show_addTCount;
    private FixedEditText show_addAddress,show_addPAddress,show_addAccount,show_addPMoblie;
    private String TAG="ShowAddtaxActivity";

    private LinearLayout mImageView;
    private Button mButton;

    private int taxbenCode;


    protected boolean useThemestatusBarColor = false;//是否使用特殊的标题栏背景颜色，android5.0以上可以设置状态栏背景色，如果不使用则使用透明色值
    protected void setStatusBar() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0及以上
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            //根据上面设置是否对状态栏单独设置颜色
            if (useThemestatusBarColor) {
                // getWindow().setStatusBarColor(getResources().getColor(R.color.colorTheme));
            } else {
                getWindow().setStatusBarColor(Color.TRANSPARENT);
            }
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4到5.0
            WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
            localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ) {//android6.0以后可以对状态栏文字颜色和图标进行修改
            getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_addtax);
        show_addType= (FixedEditText) findViewById(R.id.show_tax_invoiceType);
        show_addType.setLeadText("开票类型");
        show_addEm= (FixedEditText) findViewById(R.id.show_tax_emailAddress);
        show_addEm.setLeadText("邮箱地址");
        show_addBname= (FixedEditText) findViewById(R.id.show_tax_billingName);
        show_addBname.setLeadText("公司名称");
        show_addpID= (FixedEditText) findViewById(R.id.show_tax_proxyId);
        show_addpID.setLeadText("商业ID    ");
        show_addTaxNo= (FixedEditText) findViewById(R.id.show_tax_taxNo);
        show_addTaxNo.setLeadText("税号       ");
        show_addBank= (FixedEditText) findViewById(R.id.show_tax_taxOpenBank);
        show_addBank.setLeadText("开户行   ");
        show_addTMoblie= (FixedEditText) findViewById(R.id.show_tax_taxMobile);
        show_addTMoblie.setLeadText("手机号   ");
        show_addPMoblie= (FixedEditText) findViewById(R.id.show_tax_postMobile);
        show_addPMoblie.setLeadText("邮寄电话");
        show_addPName= (FixedEditText) findViewById(R.id.show_tax_postName);
        show_addPName.setLeadText("邮寄姓名");
        show_addAddress= (FixedEditText) findViewById(R.id.show_tax_taxAddress);
        show_addAddress.setLeadText("公司地址");
        show_addPAddress= (FixedEditText) findViewById(R.id.show_tax_postAddress);
        show_addPAddress.setLeadText("邮寄地址");
        show_addAccount= (FixedEditText) findViewById(R.id.show_tax_taxAccount);
        show_addAccount.setLeadText("对公帐号");


        mImageView= (LinearLayout) findViewById(R.id.show_tax_back);
        mButton= (Button) findViewById(R.id.show_tax_save_button);
        mImageView.setOnClickListener(this);
        mButton.setOnClickListener(this);
        setStatusBar();
         intView();


    }

    private void intView() {
        Intent intent = getIntent();
        String show_BillingName = intent.getStringExtra("show_BillingName");
        String show_TaxNo = intent.getStringExtra("show_TaxNo");
        String show_TaxMobile = intent.getStringExtra("show_TaxMobile");
        RequestParams params = new RequestParams("http://zljl.laiima.com/index.php?s=/hjs_api/Invoice/template_invoice");
        //需要带入的参数
        params.addBodyParameter("billingName", show_BillingName);
        params.addBodyParameter("taxNo", show_TaxNo);
        params.addBodyParameter("taxMobile", show_TaxMobile);
        // params.addBodyParameter("captcha", captcha);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                try {

                    JSONObject jsonObjec = new JSONObject(result);
                    String data = jsonObjec.optString("data", null);
                   // Log.e(TAG, "回调成功"+data);
                    if (!TextUtils.isEmpty(data)) {
                        JSONObject jsonObject = new JSONObject(data);
                        String show_invoiceType = jsonObject.optString("invoiceType", "");
                        String show_emailAddress = jsonObject.optString("emailAddress", "");
                        String show_proxyId = jsonObject.optString("proxyId", "");
                        String show_taxOpenBank = jsonObject.optString("taxOpenBank", "");
                        String show_taxAccount = jsonObject.optString("taxAccount", "");
                        String show_taxMobile = jsonObject.optString("taxMobile", "");
                        String show_postMobile = jsonObject.optString("postMobile", "");
                        String show_postName = jsonObject.optString("postName", "");
                        String show_taxAddress = jsonObject.optString("taxAddress", "");
                        String show_postAddress = jsonObject.optString("postAddress", "");
                        String show_taxNo = jsonObject.optString("taxNo", "");
                        String show_billingName = jsonObject.optString("billingName", "");
                        show_addType.setText(show_invoiceType);
                        show_addEm.setText(show_emailAddress);
                        show_addBname.setText(show_billingName);
                        show_addpID.setText(show_proxyId);
                        show_addTaxNo.setText(show_taxNo);
                        show_addBank.setText(show_taxOpenBank);
                        show_addTMoblie.setText(show_taxMobile);
                        show_addPMoblie.setText(show_postMobile);
                        show_addPName.setText(show_postName);
                        show_addAddress.setText(show_taxAddress);
                        show_addPAddress.setText(show_postAddress);
                        show_addAccount.setText(show_taxAccount);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (taxbenCode == 200) {
                }
                if (taxbenCode == 500) {
                    Toast.makeText(getApplicationContext(), "系统异常", Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }
            @Override
            public void onCancelled(CancelledException cex) {

            }
            @Override
            public void onFinished() {

            }
        });
    }

    @Override
    public void onClick(View v) {
        int id=v.getId();
        switch (id){
            case R.id.show_tax_back:
                this.finish();
                break;
            case R.id.show_tax_save_button:
                String show_show_addType=show_addType.getText().toString();
                String show_show_addBname=show_addBname.getText().toString();
                String show_show_addAddress=show_addAddress.getText().toString();
                String show_show_addEm=show_addEm.getText().toString();
                String show_show_addpID=show_addpID.getText().toString();
                String show_show_addTaxNo=show_addTaxNo.getText().toString();
                String show_show_addAccount=show_addAccount.getText().toString();
                String show_show_addBank=show_addBank.getText().toString();
                String show_show_addTMoblie=show_addTMoblie.getText().toString();
                String show_show_addPName=show_addPName.getText().toString();
                String show_show_addPAddress=show_addPAddress.getText().toString();
                String show_show_addPMoblie=show_addPMoblie.getText().toString();
                Intent NewAddtaxintent=new Intent(ShowAddtaxActivity.this,NewAddtaxActivity.class);
                NewAddtaxintent.putExtra("show_show_addType", show_show_addType);
                NewAddtaxintent.putExtra("show_show_addBname", show_show_addBname);
                NewAddtaxintent.putExtra("show_show_addAddress", show_show_addAddress);
                NewAddtaxintent.putExtra("show_show_addEm", show_show_addEm);
                NewAddtaxintent.putExtra("show_show_addpID", show_show_addpID);
                NewAddtaxintent.putExtra("show_show_addTaxNo", show_show_addTaxNo);
                NewAddtaxintent.putExtra("show_show_addAccount", show_show_addAccount);
                NewAddtaxintent.putExtra("show_show_addBank", show_show_addBank);
                NewAddtaxintent.putExtra("show_show_addTMoblie", show_show_addTMoblie);
                NewAddtaxintent.putExtra("show_show_addPName", show_show_addPName);
                NewAddtaxintent.putExtra("show_show_addPAddress", show_show_addPAddress);
                NewAddtaxintent.putExtra("show_show_addPMoblie", show_show_addPMoblie);
                startActivity(NewAddtaxintent);
                break;
        }

    }
}
